package com.example.vue_serve.controller;

import com.example.vue_serve.entity.TbGoods;
import com.example.vue_serve.entity.TbUser;
import com.example.vue_serve.entity.TbUserInfo;
import com.example.vue_serve.entity.TbWendu;
import com.example.vue_serve.service.TbUserService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("user")
public class TbUserController {
    @Autowired
    private TbUserService tbUserService;

    @RequestMapping(value = "/findAll",method = RequestMethod.GET)
    public List<TbUser> findAll(){
        return tbUserService.findAll();
    }
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    public String add(@RequestBody TbUser user){
        return tbUserService.add(user);
    }
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    public String updateUser(@RequestBody TbUser user){
        return tbUserService.updateUser(user);
    }

    @RequestMapping(value = "/del",method = RequestMethod.GET)
    public String delUser(@RequestParam int id){
        return tbUserService.delUser(id);
    }
    @RequestMapping(value = "/queryByName",method = RequestMethod.POST)
    public List<TbUser> queryByName(@RequestBody TbUser user){
        return tbUserService.queryByName(user);
    }
    @RequestMapping(value = "/queryLikeName",method = RequestMethod.POST)
    public List<TbUser> queryLikeName(@RequestBody TbUser user){
        return tbUserService.queryLikeName(user);
    }
    @RequestMapping(value = "/queryByTiaojian",method = RequestMethod.POST)
    public List<TbUser> queryByTiaojian(@RequestBody TbUser user){
        return tbUserService.queryByTiaojian(user);
    }
    @RequestMapping(value = "/login",method = RequestMethod.POST)
    public String login(@RequestBody TbUserInfo userInfo){
       return tbUserService.login(userInfo);
    }
    @RequestMapping(value = "/fenye",method = RequestMethod.GET)
    public List<TbUser> fenye(@Param("pageNum") int pageNum, @Param("pageSize") int pageSize){
        return tbUserService.findAllFenye(pageNum,pageSize);
    }
    @RequestMapping(value = "/findwendu",method = RequestMethod.GET)
    public List<TbWendu> findwendu(){
        return tbUserService.findAllWendu();
    }
    @RequestMapping(value = "/findgoodsByType",method = RequestMethod.GET)
    public List<TbGoods> findgoodsByType(@Param("type") int type){
        return tbUserService.findAllGoodsByType(type);
    }
}
